<template>
    <div>
        <el-dialog title="编辑收款信息" :visible="true" width="800px" :modal-append-to-body="false" :close-on-click-modal="false"
            @close="handleClose">
            <el-form id="forms" ref="forms" :rules="rulesModel" :model="form" label-width="140px">
                <el-form-item label="开户行" prop="bankName">
                    <el-input v-model="form.bankName" placeholder="请输入开户行" />
                </el-form-item>
                <el-form-item label="开户支行" prop="bankAddr">
                    <el-input v-model="form.bankAddr" type="text" placeholder="请输入开户支行" />
                </el-form-item>
                <el-form-item label="银行卡号" prop="bankCard">
                    <el-input v-model="form.bankCard" type="text" placeholder="请输入银行卡号" />
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="handleClose">取 消</el-button>
                <el-button :loading="buttonLoading" type="primary" @click="submit()">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>
    
<script>
import { SetBankInfo } from "@/api/users.js";
import { GetEnum } from '@/api/ctrls.js'
import { AESencrypt } from '@/utils/mima'
export default {
    props: {
        info: {
            default: {},
            type: Object
        },
    },
    data() {
        return {
            form: {}, // 详情实体
            rulesModel: {
                bankName: [
                    { required: true, message: '请输入开户行', trigger: 'blur' }
                ],
                bankAddr: [
                    { required: true, message: '请输入开户支行', trigger: 'blur' }
                ],
                bankCard: [
                    { required: true, message: '请输入银行卡号', trigger: 'blur' }
                ],
            },
            buttonLoading: false,

            coinList: {},// 币种枚举
        }
    },

    mounted() {
        this.setForm();
    },
    methods: {
        // 获取枚举
        async GetEnum() {
            const res = await GetEnum();
            this.coinList = res.data['Coin'];
            console.log('币种：：', this.coinList);
            if (this.form.coinid == 0) {
                this.form.coinid = Object.keys(this.coinList)[0]
            }
        },
        /**关闭弹窗 */
        handleClose() {
            this.$parent.modalStatus = 0
        },
        /**表单参数初始化 */
        setForm() {
            this.form = {
                userid: this.info.userid,
                bankName: '',
                bankAddr: '',
                bankCard: this.info.bankcard,
            };
            if(this.info.bankname.includes(',')){
                const bankList = this.info.bankname.split(",")
                this.form.bankName = bankList[0]
                this.form.bankAddr = bankList[1]
            }else{
                this.form.bankName = this.info.bankname
            }
        },
        /**（提交） */
        async submit() {
            try {
                try {
                    await this.$refs['forms'].validate()
                } catch (e) {
                    console.log(e)
                    return
                }
                const { success, msg } = await SetBankInfo(this.form)
                if (success) {
                    this.handleClose();
                }
                this.$message({
                    message: msg,
                    type: success ? 'success' : 'error'
                })
            } catch (e) {
                // 取消
                console.log(e)
            }
        },
    }
}
</script>
    
<style lang="scss" scoped>
.grid2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
}
</style>
    
    